#include "FirePit.h"

Slide* FirePit::fire = NULL;
Slide* FirePit::smoke = NULL;

FirePit::FirePit(Point<float> pos) : MovingSprite() {
	smokeAni = new Animator();
	
	loadBitmap();

	ani->go();
	smokeAni->go();

	ani->setSlide(fire, .2);
	smokeAni->setSlide(smoke, .1);

	this->start(pos);

	waitTime = -1;
}

void FirePit::loadBitmap() {
	if(fire != NULL)
		return;

	fire = new Slide();
	smoke = new Slide();
	
	fire->image = al_load_bitmap("rsc/Objects/FirePit/Fire.tga");
	fire->slideWidth = 32;
	fire->slideHeight = 32;
	fire->numSlides = 8;
	smoke->image = al_load_bitmap("rsc/Objects/FirePit/Smoke.tga");
	smoke->slideWidth = 64;
	smoke->slideHeight = 64;
	smoke->numSlides = 18;
}

void FirePit::update() {
	if(smokeAni->getCurrSlideNumber() == 0) {
		if(waitTime > 0) {
			if(al_get_time() - waitTime > 1) {
				waitTime = -1;
				smokeAni->go();
			}
		}
		else {
			waitTime = al_get_time();
			smokeAni->stop();
		}
	}
}

void FirePit::draw(Point<float> camPos) {
	al_draw_bitmap(ani->getImage(), pos.x - camPos.x + 16, pos.y - camPos.y + 8, 0);
	al_draw_bitmap(smokeAni->getImage(), pos.x - camPos.x, pos.y - camPos.y - 38, 0);
}

void FirePit::deleteImages() {
	if(fire == NULL)
		return;

	al_destroy_bitmap(fire->image);
	al_destroy_bitmap(smoke->image);
	delete fire;
	delete smoke;
	fire = NULL;
}